Skip to content

Precompile show, \, products, broadcast, concatenation and sprand of sparse Float64 arrays - #1103

Draft
ViralBShah wants to merge 4 commits into
mainfrom
vs/precompile-workload
Draft

ViralBShah wants to merge 4 commits into
mainfrom
vs/precompile-workload

Conversation

@ViralBShah

@ViralBShah ViralBShah commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

SparseArrays is not in the sysimage, and its package image holds almost no native code (a 56 KB .so), so the first call of every common operation compiles: show of a matrix takes about 0.4 s and A\b about 0.6 s.

Before (main), first calls in a fresh session, Float64 SparseMatrixCSC with Int indices:

load .ji + .so show A\b A*x 25 common operations
main 195 ms 7.7 MB + 0.06 MB 430 ms 605 ms 115 ms 1.95 s

After:

load .ji + .so show A\b A*x 25 common operations
this PR 220 ms 13.2 MB + 1.5 MB 2 ms 0.4 ms 0.0 ms 0.43 s

src/precompile.jl runs the common operations on small Float64 literals behind Base.generating_output(), the pattern Profile and Pkg use, so their native code goes into the package image; nothing runs at load. The solver calls are behind Base.USE_GPL_LIBS. sprand is included because the TTFX check's workload, S = sprand(200, 200, 0.05); kron(S, S); S * rand(200), calls it. With it, the first run of that workload compiles only rand(::Int) and takes 19.6 ms instead of 305.6 ms (median of 12, Julia 1.15.0-DEV.142, macOS arm64).

The cost is 25 ms of load time (17.4 → 26.0 ms in the same measurement), a package image about 7 MB larger, and about 4 s more to build it, which Julia's build and download carry too. A profile of the load splits the extra time about evenly. One half is reading the larger image (the .ji grows from 8.1 to 13.8 MB). The other half is checking each cached method's calls into Base and LinearAlgebra against the current method tables, which main's image needs almost none of. Loading the native code costs little. Left out: ComplexF64, which would take load to 229 ms and the image to 16 MB + 2.7 MB.

🤖 Generated with Claude Code

…se Float64 arrays

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViralBShah

Copy link
Copy Markdown
Member Author

@KristofferC Is it ok to include this in an stdlib (which is not in the system image)?

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

TTFX: 2 robust regressions, 5 robust improvements.

SparseArrays #1103 (db2d118) vs 3d92185 · run

  • SparseArrays: precompile +160.2%, run (cold) -91.9%, load+run (warm) -69.8%
  • Krylov: precompile -12.9%
  • SparseMatrixColorings: precompile -23.9%
  • All packages (geometric mean): precompile +20.0%, load+run (warm) -39.9%
Details

Julia 1.15.0-DEV.167 · Linux X64 · 4 blocks (ABBA)

metric base (s) head (s) change per block with GC off
precompile (regression) 4.17, 4.08, 4.04, 4.04 10.6, 10.4, 10.7, 10.8 +155.0%, +155.5%, +164.9%, +167.6% –
load (cold) 0.025, 0.023, 0.025, 0.023 0.039, 0.038, 0.04, 0.039 +56.5%, +67.4%, +57.8%, +67.1% +71.0%, +69.3%, +71.5%, +65.9%
run (cold) (improvement) 0.531, 0.483, 0.537, 0.493 0.04, 0.044, 0.041, 0.042 -92.5%, -90.9%, -92.4%, -91.4% -93.4%, -93.2%, -93.9%, -94.2%
load+run (warm) (improvement) 0.234, 0.227, 0.233, 0.234 0.07, 0.069, 0.072, 0.07 -70.0%, -69.7%, -69.0%, -70.3% –

Dependents (median change over blocks)

package precompile load (cold) run (cold) load+run (warm)
Krylov -12.9% improvement +43.1% – +41.1%
SparseMatrixColorings -23.9% improvement +20.9% – +20.8%
all packages (geomean) change per block with GC off
precompile (regression) +19.1%, +19.5%, +20.6%, +21.8% –
load+run (warm) (improvement) -40.1%, -40.2%, -38.3%, -39.8% –
Dependents per block

Krylov

metric base (s) head (s) change per block with GC off
precompile (improvement) 5.19, 5.14, 5.1, 5.15 4.54, 4.52, 4.42, 4.45 -12.5%, -12.1%, -13.3%, -13.5% –
load (cold) 0.036, 0.041, 0.037, 0.036 0.053, 0.052, 0.051, 0.053 +45.2%, +27.1%, +40.9%, +46.5% +39.2%, +40.8%, +38.3%, +41.5%
load+run (warm) 0.037, 0.037, 0.037, 0.036 0.052, 0.053, 0.051, 0.052 +39.0%, +43.3%, +38.4%, +45.1% –

SparseMatrixColorings

metric base (s) head (s) change per block with GC off
precompile (improvement) 5.48, 5.39, 5.36, 5.32 4.16, 4.09, 4.09, 4.16 -24.2%, -24.1%, -23.7%, -21.8% –
load (cold) 0.063, 0.063, 0.061, 0.063 0.076, 0.075, 0.074, 0.077 +20.4%, +19.2%, +21.4%, +22.6% +12.9%, +23.3%, +25.5%, +25.5%
load+run (warm) 0.062, 0.062, 0.061, 0.062 0.075, 0.074, 0.075, 0.075 +19.7%, +17.9%, +22.7%, +22.0% –

A change is robust when every block clears the threshold (precompile 8%, load (cold) 10%, run (cold) 15%, load+run (warm) 15%), the samples of the two commits do not overlap, and the medians differ by at least the floor (precompile 0.25 s, load (cold) 0.1 s, run (cold) 0.05 s, load+run (warm) 0.05 s). Load and run are also judged with the GC off, and either counts. Over all packages whose base value is at least the floor, each metric's geometric mean must clear a threshold in every block (precompile 2%, load (cold) 2%, run (cold) 3%, load+run (warm) 3%).

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.68%. Comparing base (3d92185) to head (9abaa70).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1103      +/-   ##
==========================================
+ Coverage   94.66%   94.68%   +0.02%     
==========================================
  Files          16       16              
  Lines       10437    10441       +4     
==========================================
+ Hits         9880     9886       +6     
+ Misses        557      555       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViralBShah

Copy link
Copy Markdown
Member Author

@IanButterworth Seems like TTFX is doing its job here. Pinging for you to take a look since I thought you may find it useful to see it in action.

@ViralBShah
ViralBShah marked this pull request as draft October 26, 2026 12:29
@ViralBShah ViralBShah closed this Oct 26, 2026
@IanButterworth

Copy link
Copy Markdown
Contributor

Just in case this was closed because of the precompile time, that doesn't matter for stdlibs. I'd consider this a win for run time?

@IanButterworth

Copy link
Copy Markdown
Contributor

The load time might be worth reevaluating on latest nightly.

@ViralBShah

Copy link
Copy Markdown
Member Author

I just closed it because the small savings in TTFX didn't seem to be justified by the larger system image size.

Do you think this is a good tradeoff? Good point to test it out on the latest nightly.

@ViralBShah ViralBShah reopened this Oct 26, 2026
@IanButterworth

Copy link
Copy Markdown
Contributor

Yeah I don't see any negatives here. Stdlibs come precompiled so cost during build isn't bad to the user. The rest is positive.

@IanButterworth

Copy link
Copy Markdown
Contributor

Worth adding the needs TTFX check label on the bump on the main repo to check.

@ViralBShah

Copy link
Copy Markdown
Member Author

Worth adding the needs TTFX check label on the bump on the main repo to check.

To make sure I understand, is this correct: when this PR is included in the bump upstream, the needs TTFX check label should be applied to the bump SparseArrays PR on julialang/julia?

@IanButterworth

Copy link
Copy Markdown
Contributor

Yeah.

@ViralBShah ViralBShah changed the title Precompile show, \, products, broadcast and concatenation of sparse Float64 arrays Precompile show, \, products, broadcast, concatenation and sprand of sparse Float64 arrays Oct 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants